<?php

require_once('php/lib/configured_object.php');

config('Application', 'application');

/**
 * Abstract application.
 *
 * @abstract
 * @author Pascal de Vink
 */
class Application extends ConfiguredObject {

	/**
	 * Redirects application to given url (never returns!)
	 *
	 * @param string $url URL for redirection
	 * @access public
	 */
	function redirect($url) {
		
		echo "<script language='JavaScript'>
    			window.location = '$url';
			  </script>";
		
		#header("Location: " . $url);
		exit();
	}
	
	
	function &notify($subject, $message, $debug = 'n', $van='', $aan = '') {

		// Versturen aan. (zie ws_application.php voor de instellingen)
		
		
		// overrule $to
		if ($aan <> '') {
			$to 	= $aan;
		}else {
			$to  	= $this->config['mail_to']; 		
		}
		
		// overrule $from
		if ($van <> '') {
			$from 	= $van;
		}else {
			$from 	= $this->config['mail_from']; 		
		}
		
		
		
			
		$cc  	= $this->config['mail_cc'];		
		$bcc 	= $this->config['mail_bcc']; 		
	
		include_once("php/lib/clsDump.php");
		
		if ($debug == 'y') {
			$session 	= dump($_SESSION, true);
			$post		= dump($_POST, true);
			$server		= dump($_SERVER, true);
			$get		= dump($_GET, true);
		}
			
		$message	= dump($message, true);
		
		// message
		$email = '
		<html>
		<head>
			<title>Notificatie van uConnect</title>
		</head>
		<body>
		
		<table>
			<tr>
				<td>'.$message.'
			</tr>	
		</table>';
		
		if ($debug == 'y') {
		$email .= '			
		<table width="500">
			<tr>
				<td>
					'.$session.'
				</td>
			<tr>
				<td>
					'.$post.'
				</td>
			</tr>		
			<tr>
				<td>
					'.$get.'
				</td>
			</tr>		
			<tr>
				<td>
					'.$server.'
				</td>
			</tr>
		</table>';				
		}

		$email .= '	
		</body>
		</html>
		';

		
		/*echo "to :". $to.  "<br>";
		echo "from :".$from.  "<br>";		
		echo "cc :".$cc.  "<br>";		
		echo "bcc :".$bcc.  "<br>";		*/
				
		// HTML header, the Content-type header must be set
		$headers  = 'MIME-Version: 1.0' . "\r\n";
		$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
		
		// Additional headers
		#$headers .= 'To: '.$to."\r\n";
		$headers .= 'From: '.$from."\r\n";
		$headers .= 'Cc: '.$cc."\r\n";
		$headers .= 'Bcc: '.$bcc."\r\n";
				
		// Mail it
		$new_mail = mail($to, $subject, $email, $headers);
			
	}	
	
	
	
	
	
}
?>